#ifndef __stdafx_h_
#define __stdafx_h_
#include <p33FJ64GS606.h>
#include <libpic30.h>
#define HiGHv ((unsigned int)(1.9*1024/3.3))
#define LED1 _RD3
#define LED2 _RD2
#define LED3 _RD1
#define	ALARM_UFO _RG9
#define ALARM_VFO _RG8
#define ALARM_WFO _RG7
#define ALARM_FO  _RG6
#define LED_Close() LED1=1;LED2=1;LED3=1	//000
#define LED_420mA() LED1=0;LED2=1;LED3=1	//001
#define LED_Current() LED1=1;LED2=0;LED3=1	//010
#define LED_UFO() LED1=0;LED2=0;LED3=1		//011
#define LED_VFO() LED1=1;LED2=1;LED3=0		//100
#define LED_WFO() LED1=0;LED2=1;LED3=0		//101
#define LED_FO()  LED1=1;LED2=0;LED3=0		//110
#define LED_270V() LED1=0;LED2=0;LED3=0		//111

//extern void _delay(long x);
#define FCY 40000000

/* Macros to access bytes within words and words within longs */
#define LOW_NIBBLE(x)	(x&0x0F)
#define HIGH_NIBBLE(x)	(x>>4)
#define HIGH_BYTE(x)    ((unsigned char)(((x)>>8)&0xFF))
#define LOW_BYTE(x)     ((unsigned char)((x)&0xFF))
#define HIGH_BYTE(x)    ((unsigned char)(((x)>>8)&0xFF))
#define LOW_WORD(x)     ((unsigned int)((x)&0xFFFF))
#define HIGH_WORD(x)    ((unsigned int)(((x)>>16)&0xFFFF))

#define MAKE_BYTE(h,l)	((h<<4)+(l&0x0f))
#define MAKE_INT(h,l)	(((unsigned int)h<<8)+l)
#define MAKE_WORD(h,l)	(((unsigned long)h<<16)+l)

extern void __delay_100ms(unsigned int t);
#define __delay_us(x) __delay32((unsigned long)((x)*(FCY/1000000.0)))
#define __delay_ms(x) __delay32((unsigned long)((x)*(FCY/1000.0)))
#endif
